//package com.turing.post.capitalaccounts.impl;
//
//import java.math.BigInteger;
//import java.util.List;
//
//import javax.ejb.EJB;
//import javax.ejb.Local;
//import javax.ejb.Remote;
//import javax.ejb.Stateless;
//import javax.persistence.EntityManager;
//import javax.persistence.PersistenceContext;
//import javax.persistence.Query;
//
//import com.turing.post.capitalaccounts.util.CapitalApplicationException;
//import com.turing.post.capitalaccounts.util.IssueBankAccount;
//import com.turing.post.capitalaccounts.util.IssueBankAccountDao;
//import com.turing.post.common.util.PCPSCommonDao;
//import com.turing.post.util.Config;
//import com.turing.post.util.GeneralDao;
//import com.turing.post.util.PCPSApplicationException;
//import com.turing.post.util.PCPSUtil;
//import com.turing.post.util.PCPSWebInput;
//
//@Stateless(mappedName = "capitalaccounts.impl.IssueBankAccountDaoImpl")
//@Remote
//@Local
//public class IssueBankAccountDaoImpl implements IssueBankAccountDao {
//	/**
//	 * 实体管理器
//	 */
//	@PersistenceContext
//	protected EntityManager _em;
//
//	@EJB(mappedName = "common.impl.PCPSCommonDaoImpl")
//	private PCPSCommonDao pcpsCommonDaoImpl;
//
//	@Override
//	public IssueBankAccount getIssueBankAccountId(BigInteger issueBankAccountId) {
//		return _em.find(IssueBankAccount.class, issueBankAccountId);
//	}
//
//	@Override
//	public void insertIssueBankAccount(PCPSWebInput webInput,
//			IssueBankAccount obj) throws PCPSApplicationException {
//		// 平台机构管理员归属机构号为空
//		if (!PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
//			String issueCompanyNo = PCPSUtil.getIssueCompanyNo(webInput);
//			obj.setIssueCompanyNo(issueCompanyNo);
//		} else {
//			throw new CapitalApplicationException(
//					CapitalApplicationException.ERRCODE_CATEGORY_APPLICATION,
//					"", "超级管理员无法添加自己归属下的发卡方银行帐户信息!");
//		}
//		obj.setIssueBankAccountId(pcpsCommonDaoImpl.getUniqueIntegerKey());
//		// 判断BankAccountId银行帐户ID是否重复
//		if (getIssueBankAccountByBankAccountId(obj.getBankAccountId()) != null) {
//			throw new CapitalApplicationException(
//					CapitalApplicationException.ERRCODE_CATEGORY_APPLICATION,
//					"", "发卡方银行帐户" + obj.getBankAccountId() + "已经存在!");
//		}
//		GeneralDao.insert(_em, obj);
//	}
//
//	@Override
//	public void deleteIssueBankAccount(IssueBankAccount obj)
//			throws PCPSApplicationException {
//		String sql = "delete from IssueBankAccount where IssueBankAccountId="
//				+ obj.getIssueBankAccountId();
//		Query query = _em.createNativeQuery(sql);
//		try {
//			query.executeUpdate();
//		} catch (Exception e) {
//			throw new CapitalApplicationException(
//					CapitalApplicationException.ERRCODE_CATEGORY_APPLICATION,
//					"", "删除发卡方银行帐户信息失败，该账户已被引用!");
//		}
//	}
//
//	@SuppressWarnings("unchecked")
//	@Override
//	public List<IssueBankAccount> getIssueBankAccountListByIssueCompanyNo(
//			PCPSWebInput webInput, Integer page) {
//		String sql = "";
//		int maxResult = Config.PAGE_SIZE;
//		int startPosition = maxResult * page;
//		// 平台机构管理员归属机构号为空
//		if (!PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
//			String issueCompanyNo = PCPSUtil.getIssueCompanyNo(webInput);
//			sql = "select t.* from IssueBankAccount t where IssueCompanyNo='"
//					+ issueCompanyNo + "' order by IssueBankAccountId";
//		} else {
//			sql = "select t.* from IssueBankAccount t order by IssueBankAccountId";
//		}
//		Query query = _em.createNativeQuery(sql, IssueBankAccount.class)
//				.setFirstResult(startPosition).setMaxResults(maxResult);
//		return query.getResultList();
//	}
//
//	@Override
//	public BigInteger getIssueBankAccountTotalByIssueCompanyNo(
//			PCPSWebInput webInput) {
//		String sql = "";
//		// 平台机构管理员归属机构号为空
//		if (!PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
//			String issueCompanyNo = PCPSUtil.getIssueCompanyNo(webInput);
//			sql = "select nvl(count(*),0) from IssueBankAccount t where IssueCompanyNo='"
//					+ issueCompanyNo + "'";
//		} else {
//			sql = "select nvl(count(*),0) from IssueBankAccount t";
//		}
//		Query query = _em.createNativeQuery(sql);
//		return new BigInteger(query.getSingleResult().toString());
//	}
//
//	@Override
//	public void updateIssueBankAccount(IssueBankAccount obj)
//			throws PCPSApplicationException {
//		IssueBankAccount issueBankAccount = getIssueBankAccountId(obj
//				.getIssueBankAccountId());
//		if (issueBankAccount != null) {
//			if (obj.getBankAccountId() != null) {
//				if (obj.getBankAccountId().compareTo(
//						issueBankAccount.getBankAccountId()) != 0) {
//					if (getIssueBankAccountByBankAccountId(obj
//							.getBankAccountId()) != null) {
//						throw new CapitalApplicationException(
//								CapitalApplicationException.ERRCODE_CATEGORY_APPLICATION,
//								"", "发卡方银行帐户" + obj.getBankAccountId()
//										+ "已经存在!");
//					}
//				}
//			}
//			// 只修改备注信息
//			issueBankAccount.setBankAccountId(obj.getBankAccountId());
//			issueBankAccount.setRemark(obj.getRemark());
//			GeneralDao.update(_em, issueBankAccount);
//		} else {
//			throw new CapitalApplicationException(
//					CapitalApplicationException.ERRCODE_CATEGORY_APPLICATION,
//					"", "发卡方银行帐户信息修改失败，待修改银行账户未找到!");
//		}
//	}
//
//	@SuppressWarnings("unchecked")
//	@Override
//	public IssueBankAccount getIssueBankAccountByBankAccountId(
//			BigInteger bankAccountId) {
//		String sql = "select * from IssueBankAccount t where BankAccountId="
//				+ bankAccountId + "";
//		Query query = _em.createNativeQuery(sql, IssueBankAccount.class);
//		List<IssueBankAccount> issueBankAccountList = query.getResultList();
//		if (issueBankAccountList.size() > 0) {
//			return issueBankAccountList.get(0);
//		} else {
//			return null;
//		}
//	}
//
//	@SuppressWarnings("unchecked")
//	@Override
//	public List<IssueBankAccount> getIssueBankAccountDropdown(
//			PCPSWebInput webInput) {
//		String sql = "";
//		if (!PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
//			String issueCompanyNo = PCPSUtil.getIssueCompanyNo(webInput);
//			sql = "select t.* from IssueBankAccount t where IssueCompanyNo='"
//					+ issueCompanyNo + "' order by IssueBankAccountId";
//		} else {
//			return null;
//			// sql = "select t.* from IssueBankAccount t order by
//			// IssueBankAccountId";
//		}
//		Query query = _em.createNativeQuery(sql, IssueBankAccount.class);
//		return query.getResultList();
//	}
//}